package com.ziyueyuwen.xiniao.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.suyeer.basic.util.DateUtil;
import com.ziyueyuwen.xiniao.bean.ZyClassLessonInfo;
import com.ziyueyuwen.xiniao.bean.ZyLessonMessageTask;
import com.ziyueyuwen.xiniao.bean.ZyMessageDetails;
import com.ziyueyuwen.xiniao.bean.ZyUser;
import com.ziyueyuwen.xiniao.bean.homework.HomeworkRecordStatusDO;
import com.ziyueyuwen.xiniao.bean.vo.ZyClassUserVO;
import com.ziyueyuwen.xiniao.bean.vo.ZyLessonVO;
import com.ziyueyuwen.xiniao.dao.ZyClassLessonInfoMapper;
import com.ziyueyuwen.xiniao.dao.ZyLessonMessageTaskMapper;
import com.ziyueyuwen.xiniao.dao.ZyMessageDetailsMapper;
import com.ziyueyuwen.xiniao.enums.MessageTypeEnum;
import com.ziyueyuwen.xiniao.enums.ThirdPartyTypeEnum;
import com.ziyueyuwen.xiniao.enums.UserIdentityEnum;
import com.ziyueyuwen.xiniao.service.*;
import com.ziyueyuwen.xiniao.thirdpart.bean.wx.WxTemplate;
import com.ziyueyuwen.xiniao.thirdpart.util.WxUtil;
import com.ziyueyuwen.xiniao.util.EEOUtil;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.Date;

import static com.ziyueyuwen.xiniao.enums.HomeworkStatusEnum.FINISHED;
import static com.ziyueyuwen.xiniao.enums.MessageTypeEnum.MESSAGE_LESSON_EXPANSION;
import static com.ziyueyuwen.xiniao.util.ConstUtil.SYS_CONFIG_DATA;
import static com.ziyueyuwen.xiniao.util.DateUtil.DEFAULT_FORMAT_PATTERN_3;

/**
 * @author wancheng  on 2018/12/19.
 */
@Service
public class WxMessageServiceImpl implements WxMessageService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final static String FIRST = "first";
    private final static String KEYWORD1 = "keyword1";
    private final static String KEYWORD2 = "keyword2";
    private final static String KEYWORD3 = "keyword3";
    private final static String REMARK = "remark";

    private final static String DEFAULT_FORMAT_PATTERN = "yyyy年MM月dd日 HH:mm";
    /**
     * 课前预习
     * /beforeclass/:subjectId/:homeworkIndex/:lessonId/:classId
     */
    private final static String URL_REMIND_INFLATED = "%s/beforeclass/%s/%s/%s/%s";
    /**
     * 课后总结
     * /classconclusion/:subjectId/:homeworkIndex/:lessonId
     */
    private final static String URL_LESSON_SUMMARIZE = "%s/classconclusion/%s/%s/%s/%s";
    /**
     * 作业链接
     * /starthomework/:lessonId/:subjectId/:homeworkIndex
     */
    private final static String URL_LESSON_HOMEWORK = "%s/starthomework/%s/%s/%s";
    /**
     * 作业报告
     * homeworkReport/:lessonId/:subjectId/:homeworkIndex
     */
    private final static String URL_HOMEWORK_CORRECT = "%s/homeworkReport/%s/%s/%s/2";
    /**
     * 课后拓展
     * /classexpand/:subjectId/:homeworkIndex/:lessonId
     */
    private final static String URL_LESSON_EXPANSION = "%s/classexpand/%s/%s/%s";
    /**
     * 课堂报告
     * ///feedback/subject/lessonNum/lessonId/13120335328
     */
    private final static String URL_LESSON_REPORT = "%s/feedback/%s/%s/%s/%s";
    @Autowired
    ZyClassLessonInfoMapper zyClassLessonInfoMapper;
    @Autowired
    ThirdPartService thirdPartService;
    @Autowired
    ZyMessageDetailsMapper zyMessageDetailsMapper;
    @Autowired
    LessonService lessonService;
    @Autowired
    ZyLessonMessageTaskMapper zyLessonMessageTaskMapper;
    @Autowired
    HomeworkRecordService homeworkRecordService;
    @Autowired
    ClassUserService classUserService;
    @Autowired
    UserService userService;

    /**
     * 课前
     * 消息模板:
     * Hi~您报名的直播马上开始啦！
     * 课程名称：5小时西班牙语入门
     * 时间：2015年12月16日18
     * 点击我去上直播课！INFLATED
     */
    @Override
    @Async
    public void sendClassRemindInflated(String userAccount, Integer lessonId, Integer taskId) {
        String titleLessonInflated = "课前预习来了，快来看看下次课的精彩之处吧";
        String contentLessonInflated = "凡事预则立，不预则废。子曰语文提醒，看看下节课我们应该提前预习什么吧。";
        String openId = thirdPartService.getOpenId(userAccount);

        String domainName = SYS_CONFIG_DATA.getDomainName();
        ZyLessonVO lessonVO = lessonService.getClassAndCourseByLessonId(lessonId);
        Integer subjectId = lessonVO.getCourse().getSubjectId() == null ? 0 : lessonVO.getCourse().getSubjectId();
        String url = String.format(URL_REMIND_INFLATED, domainName, subjectId, lessonVO.getLessonIndex(), lessonId, lessonVO.getClassInfo().getId());

        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);
        ZyClassUserVO teacher = classUserService.getTeacher(lessonId);
        String dateString = DateFormatUtils.format(zyClassLessonInfo.getBeginTime(), DEFAULT_FORMAT_PATTERN);
        ZyLessonVO lessonCourseInfo = lessonService.getClassAndCourseByLessonId(lessonId);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonInflated)
                .put(KEYWORD1, String.format("%s-%s", lessonCourseInfo.getCourse().getCourseName(), zyClassLessonInfo.getLessonIndex()))
                .put(KEYWORD2, teacher.getUserName())
                .put(KEYWORD3, dateString)
                .put(REMARK, contentLessonInflated);
        Boolean isSend = WxUtil.sendLessonRemindInflated(openId, url, wxTemplate);
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_INFLATED, isSend);
    }

    @Override
    @Async
    public void sendLessonBeforeOneHour(String userAccount, Integer lessonId, Integer taskId) {
        String titleLessonBeforeOneHour = "还有1小时就要上课啦，记得要准时哟";
        String contentLessonBeforeOneHour = "乐在其中。子曰语文提醒，还有1小时就开启你的快乐学习之旅了哦。";
        String openId = thirdPartService.getOpenId(userAccount);
        String url = "";
        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);
        String dateString = DateFormatUtils.format(zyClassLessonInfo.getBeginTime(), DEFAULT_FORMAT_PATTERN);
        ZyLessonVO lessonCourseInfo = lessonService.getClassAndCourseByLessonId(lessonId);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonBeforeOneHour)
                .put(KEYWORD1, String.format("%s-%s", lessonCourseInfo.getCourse().getCourseName(), zyClassLessonInfo.getLessonIndex()))
                .put(KEYWORD2, dateString)
                .put(REMARK, contentLessonBeforeOneHour);
        Boolean isSend = WxUtil.sendLessonRemind(openId, url, wxTemplate);
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_BEFORE_ONE_HOUR, isSend);
    }

    @Override
    @Async
    public void sendLessonBeforeFifteenMinute(String userAccount, Integer lessonId, Integer taskId) {
        String titleLessonBeforeFifteenMinute = "还有5分钟，老师喊你快点儿进教室了";
        String contentLessonBeforeFifteenMinute = "三人行，必有我师焉。子曰语文提醒，距离你和你的小伙伴一起学习还有5分钟。请在上课前退出不必要的软件，插上网线或者选择一个靠近路由器的安静环境，打开房间灯，插上耳机或麦克风。";
        String openId = thirdPartService.getOpenId(userAccount);
        String url = "";
        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);
        String dateString = DateFormatUtils.format(zyClassLessonInfo.getBeginTime(), DEFAULT_FORMAT_PATTERN);
        ZyLessonVO lessonCourseInfo = lessonService.getClassAndCourseByLessonId(lessonId);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonBeforeFifteenMinute)
                .put(KEYWORD1, String.format("%s-%s", lessonCourseInfo.getCourse().getCourseName(), zyClassLessonInfo.getLessonIndex()))
                .put(KEYWORD2, dateString)
                .put(REMARK, contentLessonBeforeFifteenMinute);
        Boolean isSend = WxUtil.sendLessonRemind(openId, url, wxTemplate);
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_BEFORE_FIFTEEN_MINUTE, isSend);
    }

    /**
     * 小红同学今天的课程开始了
     * 课程内容：进阶绘画
     * 课程时长：40分钟
     * 出勤情况：到课/迟到
     * 点击查看课堂教学实时监控
     *
     * @param userAccount
     * @param lessonId
     */
    @Override
    @Async
    public void sendLessonSignIn(String userAccount, Integer lessonId, Integer taskId) {
        String titleLessonSignIn = "已经看到孩子在教室认真上课了哟";
        String contentLessonSignIn = "乐以忘忧。子曰语文提醒，孩子已经进入教室开心学习，点击即可查看孩子实时上课情况。";
        String openId = thirdPartService.getOpenId(userAccount);
        String url = "";
        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);
        String ifSignInString = "迟到";
        Integer minutes = com.ziyueyuwen.xiniao.util.DateUtil.caleMinute(zyClassLessonInfo.getBeginTime(), zyClassLessonInfo.getEndTime(), true);
        ZyLessonVO courseInfo = lessonService.getClassAndCourseByLessonId(lessonId);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonSignIn)
                .put(KEYWORD1, String.format("%s-%s", courseInfo.getCourse().getCourseName(), zyClassLessonInfo.getLessonIndex()))
                .put(KEYWORD2, String.format("%s分钟", minutes))
                .put(KEYWORD3, ifSignInString)
                .put(REMARK, contentLessonSignIn);
        Boolean isSend = WxUtil.sendLessonSignIn(openId, url, wxTemplate);
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_INFLATED, isSend);
    }

    @Override
    @Async
    public void sendLessonReplay(String userAccount, Integer lessonId, Integer taskId) {
        String titleLessonUrlReplay = "还有哪里听不懂？看看课程回放吧";
        String contentLessonUrlReplay = "温故而知新。子曰语文提醒，点击查看课程回放，重温精彩课堂，找寻你的新发现。";
        String openId = thirdPartService.getOpenId(userAccount);

        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);
        String url = EEOUtil.getWebcastUrl(zyClassLessonInfo.getEeoCourseId(), zyClassLessonInfo.getEeoLessonId());
        String dateString = DateFormatUtils.format(zyClassLessonInfo.getBeginTime(), DEFAULT_FORMAT_PATTERN);
        ZyLessonVO courseInfo = lessonService.getClassAndCourseByLessonId(lessonId);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonUrlReplay)
                .put(KEYWORD1, String.format("%s-%s", courseInfo.getCourse().getCourseName(), zyClassLessonInfo.getLessonIndex()))
                .put(KEYWORD2, dateString)
                .put(REMARK, contentLessonUrlReplay);
        Boolean isSend = false;
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_URL_REPLAY, isSend);
    }

    /**
     * @param userAccount
     * @param lessonId
     */
    @Override
    @Async
    public void sendLessonSummarize(String userAccount, Integer lessonId, Integer taskId) {
        String titleLessonUrlSummarize = "没有及时记笔记？看看老师的课后总结吧";
        String contentLessonUrlSummarize = "学而时习之，不亦乐乎。子曰语文提醒，课后总结，让你带走满满干货。";
        String openId = thirdPartService.getOpenId(userAccount);
        //url
        String domainName = SYS_CONFIG_DATA.getDomainName();
        ZyLessonVO lessonVO = lessonService.getClassAndCourseByLessonId(lessonId);
        Integer subjectId = lessonVO.getCourse().getSubjectId() == null ? 0 : lessonVO.getCourse().getSubjectId();
        String url = String.format(URL_LESSON_SUMMARIZE, domainName, subjectId, lessonVO.getLessonIndex(), lessonId, lessonVO.getClassInfo().getId());
        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);
        String dateString = DateFormatUtils.format(zyClassLessonInfo.getBeginTime(), DEFAULT_FORMAT_PATTERN);
        ZyLessonVO courseInfo = lessonService.getClassAndCourseByLessonId(lessonId);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonUrlSummarize)
                .put(KEYWORD1, String.format("%s-%s", courseInfo.getCourse().getCourseName(), zyClassLessonInfo.getLessonIndex()))
                .put(KEYWORD2, dateString)
                .put(REMARK, contentLessonUrlSummarize);
        Boolean isSend = WxUtil.sendLessonSummarize(openId, url, wxTemplate);
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_URL_SUMMARIZE, isSend);
    }

    /**
     * 模板:
     * 您的课程有新作业了
     * 课程名称：中央美术学院2015年度城市设计
     * 作业名称：Final Draft
     * 截止日期：2016年01月07日
     * 请在截止日期之前上传作业。
     *
     * @param userAccount
     * @param lessonId
     */
    @Override
    @Async
    public void sendLessonHomework(String userAccount, Integer lessonId, Integer taskId) {
        String titleLessonHomework = "有一份精美的作业需要你查收";
        String contentLessonHomework = "熟能生巧。子曰语文提醒，下课不练习，上课白听讲。认真完成作业才能保证知识更好地吸收。";
        String openId = thirdPartService.getOpenId(userAccount);
        String url = getHomeworkUrl(URL_LESSON_HOMEWORK, lessonId);
        ;
        ZyLessonVO lessonVO = lessonService.getClassAndCourseByLessonId(lessonId);
        ZyClassLessonInfo next = zyClassLessonInfoMapper.getNextLesson(lessonId);
        String homeworkName = lessonVO.getCourse().getCourseName() + "-" + lessonVO.getLessonIndex() + "课后作业";
        String expiryDate = "";
        if (next != null) {
            expiryDate = com.ziyueyuwen.xiniao.util.DateUtil.date2Str(next.getBeginTime());
        }
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonHomework)
                .put(KEYWORD1, lessonVO.getCourse().getCourseName())
                .put(KEYWORD2, homeworkName)
                .put(KEYWORD3, expiryDate)
                .put(REMARK, contentLessonHomework);
        Boolean isSend = WxUtil.sendLessonHomework(openId, url, wxTemplate);
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_HOMEWORK, isSend);
    }

    /**
     * 同学您好，您已完成下列写作任务并成功交卷
     * 任务名称：议论文30分钟写作训练
     * 任务内容：第三讲作业-《我看高考》
     * 完成情况：全文932字，满足交卷要
     * 求老师正在阅卷，请务必按时完成剩余作业，以免逾期被扣除学分
     *
     * @param userAccount
     * @param lessonId
     */
    @Override
    @Async
    public void sendLessonHomeworkCommit(String userAccount, Integer lessonId) {
        String titleLessonHomeworkCommit = "及时完成作业，给你点赞\uD83D\uDC4D";
        String contentLessonHomeworkCommit = "有志者事竟成。子曰语文提醒，完成作业这件事，你就是那个有志者哦。";
        String openId = thirdPartService.getOpenId(userAccount);
        String url = "xx";
        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);

    }

    /**
     * 您好，本次课程的课后作业需要您及时提交
     * 截止时间：12月30日 晚上 11:00
     * 提交方式：微信公众号的作业提交功能在线提交
     * 有任何问题请联系我们的客服，感谢您的参与
     *
     * @param userAccount
     * @param lessonId
     */
    @Override
    @Async
    public void sendLessonHomeworkUnCommit(String userAccount, Integer lessonId, Integer taskId) {
        //此处查询学生是否提交完作业
        HomeworkRecordStatusDO status = homeworkRecordService.getHomeworkStatus(userAccount, lessonId);
        if (status != null && FINISHED.equals(status.getStatus())) {
            return;
        }
        String titleLessonHomeworkUnCommit = "老师还没看到你的作业，赶快完成它吧";
        String contentLessonHomeworkUnCommit = "业精于勤荒于嬉，行成于思毁于随。子曰语文提醒，老师就等你的作业了，快快提交哦。";
        String openId = thirdPartService.getOpenId(userAccount);
        String url = getHomeworkUrl(URL_LESSON_HOMEWORK, lessonId);
        ZyClassLessonInfo next = zyClassLessonInfoMapper.getNextLesson(lessonId);
        String expiryDate = "";
        if (next != null) {
            expiryDate = com.ziyueyuwen.xiniao.util.DateUtil.date2Str(next.getBeginTime());
        }
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonHomeworkUnCommit)
                .put(KEYWORD1, expiryDate)
                .put(KEYWORD2, "微信公众号的作业提交功能在线提交")
                .put(REMARK, contentLessonHomeworkUnCommit);
        Boolean isSend = WxUtil.sendLessonHomeworkUnCommit(openId, url, wxTemplate);
        getMessageDetails(lessonId, taskId, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_HOMEWORK_UN_COMMIT, isSend);
    }

    /**
     * 同学你好，老师已完成点评
     * 课程名：英语口语练习
     * 点评人：李老师
     * 点评时间：2014年7月21日 18:36
     * 查看点评详情
     *
     * @param userAccount
     * @param lessonId
     */
    @Override
    @Async
    public void sendLessonHomeworkCorrect(String userAccount, String teacherName, Integer lessonId, Date correctTime) {
        String titleLessonHomeworkCorrect = "少年，你的作业已经批改完成，看看老师说了啥";
        String contentLessonHomeworkCorrect = "师者，所以传道受业解惑也。子曰语文提醒，小朋友的作业，老师已批改，快看老师怎么说。";
        String openId = thirdPartService.getOpenId(userAccount);
        String url = getHomeworkUrl(URL_HOMEWORK_CORRECT, lessonId);
        String correctTimeString = com.ziyueyuwen.xiniao.util.DateUtil.date2Str(correctTime);
        ZyClassLessonInfo zyClassLessonInfo = zyClassLessonInfoMapper.selectByPrimaryKey(lessonId);
        ZyLessonVO courseInfo = lessonService.getClassAndCourseByLessonId(lessonId);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, titleLessonHomeworkCorrect)
                .put(KEYWORD1, String.format("%s-%s", courseInfo.getCourse().getCourseName(), zyClassLessonInfo.getLessonIndex()))
                .put(KEYWORD2, teacherName)
                .put(KEYWORD3, correctTimeString)
                .put(REMARK, contentLessonHomeworkCorrect);
        Boolean isSend = WxUtil.sendLessonHomeworkCorrect(openId, url, wxTemplate);
        getMessageDetails(lessonId, 0, userAccount, openId, url, wxTemplate, MessageTypeEnum.MESSAGE_LESSON_HOMEWORK_CORRECT, isSend);

    }

    @Override
    public void saveLessonExpansion(String userAccount, Integer lessonId, Integer taskId) {
        String url = getUrl(URL_LESSON_EXPANSION, lessonId);
        getMessageDetails(lessonId, taskId, userAccount, null, url, null, MESSAGE_LESSON_EXPANSION, false);
    }

    public ZyMessageDetails getMessageDetails(Integer lessonId,
                                              Integer taskId,
                                              String userAccount,
                                              String openId,
                                              String url,
                                              WxTemplate wxTemplate,
                                              MessageTypeEnum typeEnum,
                                              Boolean ifSend
    ) {
        Date createTime = new Date();
        ZyMessageDetails details = new ZyMessageDetails();
        details.setLessonId(lessonId)
                .setTaskId(taskId)
                .setUserAccount(userAccount)
                .setThirdPartyId(openId)
                .setThirdPartyType(ThirdPartyTypeEnum.WEI_XIN)
                .setCreateTime(createTime)
                .setMessageContent(JSON.toJSONString(wxTemplate))
                .setMessageType(typeEnum)
                .setMessageUrl(url)
                .setUserIdentity(UserIdentityEnum.STUDENT)
                .setIfSendSuccess(ifSend);
        zyMessageDetailsMapper.insertSelective(details);
        if (ifSend != null && !ifSend) {
            logger.info("消息发送失败,手机号码为:{}", userAccount);
        }
        return details;
    }

    private String getUrl(String urlTemplate, Integer lessonId) {
        String domainName = SYS_CONFIG_DATA.getDomainName();
        ZyLessonVO lessonVO = lessonService.getClassAndCourseByLessonId(lessonId);
        Integer subjectId = lessonVO.getCourse().getSubjectId() == null ? 0 : lessonVO.getCourse().getSubjectId();
        String url = String.format(urlTemplate, domainName, subjectId, lessonVO.getLessonIndex(), lessonId);
        return url;
    }

    private String getHomeworkUrl(String urlTemplate, Integer lessonId) {
        String domainName = SYS_CONFIG_DATA.getDomainName();
        ZyLessonVO lessonVO = lessonService.getClassAndCourseByLessonId(lessonId);
        Integer subjectId = lessonVO.getCourse().getSubjectId() == null ? 0 : lessonVO.getCourse().getSubjectId();
        String url = String.format(urlTemplate, domainName, lessonId, subjectId, lessonVO.getLessonIndex());
        return url;
    }

    @Override
    public void sendLessonReport(String openId, Integer lessonId, String studentAccount, String teacherName) {
        /**
         * 课堂报告
         * ///feedback/subjectId/lessonId/lessonIndex/account
         */
        ZyLessonVO lesson = lessonService.getClassAndCourseByLessonId(lessonId);
        String url = getReportUrl(lessonId, studentAccount);
        String beginTime = com.ziyueyuwen.xiniao.util.DateUtil.date2Str(lesson.getBeginTime(), DEFAULT_FORMAT_PATTERN_3);
        String endTime = com.ziyueyuwen.xiniao.util.DateUtil.date2Str(lesson.getEndTime(), DEFAULT_FORMAT_PATTERN_3);
        WxTemplate wxTemplate = new WxTemplate()
                .put(FIRST, "课堂报告")
                .put(KEYWORD1, lesson.getClassLessonName())
                .put(KEYWORD2, teacherName)
                .put(KEYWORD3, beginTime + " - " + endTime)
                .put(REMARK, "感谢家长的支持！");
        Boolean isSend = WxUtil.sendLessonHomeworkCorrect(openId, url, wxTemplate);
    }

    public String getReportUrl(Integer lessonId, String studentAccount) {
        ZyLessonVO lesson = lessonService.getClassAndCourseByLessonId(lessonId);
        Integer subjectId = lesson.getCourse().getSubjectId() == null ? 0 : lesson.getCourse().getSubjectId();
        String url = String.format(URL_LESSON_REPORT, SYS_CONFIG_DATA.getDomainName(), subjectId, lesson.getLessonIndex(), lesson.getId(), studentAccount);
        return url;
    }
}
